package com.vm.adapter;

import java.util.List;
import com.vm.fragment.FoundFragment;
import com.wwtscapp.apk.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

@SuppressLint("InflateParams")
@SuppressWarnings("deprecation")
public class FoundImageAdapter extends BaseAdapter {
	private List<String> imageUrls; // 图片地址list
	private Context context;
	private FoundImageAdapter self;
	FoundFragment foundFragment = new FoundFragment();
	Uri uri;
	Intent intent;
	ImageView imageView;
	int current_point = 0;
	public static Handler mainHandler;
	public static Integer[] imgs = { R.drawable.found, R.drawable.viwepager_0,
			R.drawable.viwepager_1, R.drawable.viwepager_2,
			R.drawable.viwepager_3 };

	public FoundImageAdapter(Context context) {
		this.context = context;
		this.self = this;
	}

	public int getCount() {
		return Integer.MAX_VALUE;
	}

	public Object getItem(int position) {
		return imageUrls.get(position % imgs.length);
	}

	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("HandlerLeak")
	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			try {
				switch (msg.what) {
				case 0: {
					self.notifyDataSetChanged();
				}
					break;
				}

				super.handleMessage(msg);
			} catch (Exception e) {
			}
		}
	};

	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.item,
					null); // 实例化convertView
			Gallery.LayoutParams params = new Gallery.LayoutParams(
					Gallery.LayoutParams.WRAP_CONTENT,
					Gallery.LayoutParams.WRAP_CONTENT);
			convertView.setLayoutParams(params);
			convertView.setTag(imgs);

		} else {

		}

		imageView = (ImageView) convertView.findViewById(R.id.gallery_image);
		imageView.setImageResource(imgs[position % imgs.length]);
		// 设置缩放比例：保持原样
		imageView.setScaleType(ImageView.ScaleType.FIT_XY);
		Message msg = new Message();
		msg.what = 2;
		msg.obj = position % imgs.length;
		mainHandler.sendMessage(msg);
		// changePointView(position % imgs.length);
		return convertView;

	}

	// public void changePointView(int cur) {
	// LinearLayout pointLinear = (LinearLayout) LayoutInflater
	// .from(context.getApplicationContext())
	// .inflate(R.layout.found, null)
	// .findViewById(R.id.gallery_point_linear);
	//
	// View current_view = pointLinear.getChildAt(current_point);
	// View target_view = pointLinear.getChildAt(cur);
	// if (current_view != null && target_view != null) {
	// ImageView pointView = (ImageView) current_view;
	// ImageView curPointView = (ImageView) target_view;
	// pointView.setBackgroundResource(R.drawable.feature_point);
	// curPointView.setBackgroundResource(R.drawable.feature_point_cur);
	// current_point = cur;
	//
	// }
	// }
}
